﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class SupplyItem : MonoBehaviour
{
    public ESupplyType type;

    public Vector2 offset;

    public Vector2 spacing;

    private int m_Index;
    
    private SpriteRenderer _spriteRenderer;

    public Sprite[] sprites;
    
    private void Awake()
    {
        _spriteRenderer = GetComponent<SpriteRenderer>();
    }

    private void Update()
    {
        transform.localPosition = offset + m_Index * spacing;
    }

    public void SetSupplyData(ESupplyType supplyType, int index)
    {
        type = supplyType;
        gameObject.SetActive(true);
        SetSprite();
        SetPositoion(index);
    }
    
    public void SetInactive()
    {
        gameObject.SetActive(false);
    }
    
    public void SetSprite()
    {
        _spriteRenderer.sprite = sprites[(int)type];
    }
    
    public void SetPositoion(int index)
    {
        this.m_Index = index;
    }
}
